<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h3></h3>

    <script>
        function ajax(url,data, method, callback) {
            let x = new XMLHttpRequest()
            

            let str = Object.keys(data).map(item=>`${item}=${data[item]}`).join("&")
            console.log(str);
            if(method === "get"){
                x.open(method, url+"?"+str )
                x.send()
            }else{
                x.open(method, url )
                x.setRequestHeader("Content-type","application/x-www-form-urlencoded")
                x.send(str)
            }
            

            // x.responseType = "json"

            x.onreadystatechange = function () {
                if (x.readyState === 4) {
                    if (x.status >= 200 && x.status < 300) {
                        let obj = x.response

                        callback(obj)
                    }
                }
            }
        }

        ajax("http://localhost/postServer",{a:"c",name:"laowang"}, "post", function (obj) {
            // document.querySelector("h3").innerHTML = obj.hitokoto
            console.log(obj);
        })

    </script>
</body>

</html>